<template>
  <div class="charts-container">
    <div class="charts-row">
      <!-- 月收支趋势图 -->
      <el-card shadow="hover" class="chart-card">
        <div class="chart-header">
          <div class="chart-title">月收支趋势</div>
          <div class="chart-actions">
            <el-radio-group fill="#3370ff" v-model="trendChartTypeMonth" size="small">
              <el-radio-button value ="line">折线图</el-radio-button>
              <el-radio-button value ="bar">柱状图</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <TrendChart
          :data="trendDataMonth"
          :type="trendChartTypeMonth"
          class="chart-container"
        />
      </el-card>
      <!--日收支趋势图-->
      <el-card shadow="hover" class="chart-card">
        <div class="chart-header">
          <div class="chart-title">日收支趋势</div>
          <div class="chart-actions">
            <el-radio-group fill="#3370ff" v-model="trendChartTypeDay" size="small">
              <el-radio-button value="line">折线图</el-radio-button>
              <el-radio-button value="bar">柱状图</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <TrendChart
          :data="trendDataDay"
          :type="trendChartTypeDay"
          class="chart-container"
        />
      </el-card>
    </div>

    <div class="charts-row">
      <!-- 成员收入对比 -->
      <el-card shadow="hover" class="chart-card">
        <div class="chart-header">
          <div class="chart-title">成员收入对比</div>
          <div class="chart-actions">
            <el-radio-group fill="#3370ff" v-model="memberIncomeChartType" size="small">
              <el-radio-button value="bar">柱状图</el-radio-button>
              <el-radio-button value="horizontal">条形图</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <MemberBarChart
          :data="memberIncome"
          :type="memberIncomeChartType"
          class="chart-container"
        />
      </el-card>

      <!-- 成员支出对比 -->
      <el-card shadow="hover" class="chart-card">
        <div class="chart-header">
          <div class="chart-title">成员支出对比</div>
          <div class="chart-actions">
            <el-radio-group fill="#3370ff" v-model="memberExpenseChartType" size="small">
              <el-radio-button value="bar">柱状图</el-radio-button>
              <el-radio-button value="horizontal">条形图</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <MemberBarChart
          :data="memberExpenses"
          :type="memberExpenseChartType"
          class="chart-container"
        />
      </el-card>
    </div>

    <div class="charts-row">
      <!-- 收入分类占比 -->
      <el-card shadow="hover" class="chart-card">
        <div class="chart-header">
          <div class="chart-title">收入分类占比</div>
          <div class="chart-actions">
            <el-radio-group fill="#3370ff" v-model="incomeChartType" size="small">
              <el-radio-button value="pie">饼图</el-radio-button>
              <el-radio-button value="rose">玫瑰图</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <CategoryPieChart
          :data="incomeCategories"
          :type="incomeChartType"
          title="收入分类"
          class="chart-container"
        />
      </el-card>
      <!-- 支出分类占比 -->
      <el-card shadow="hover" class="chart-card">
        <div class="chart-header">
          <div class="chart-title">支出分类占比</div>
          <div class="chart-actions">
            <el-radio-group fill="#3370ff" v-model="expenseChartType" size="small">
              <el-radio-button value="pie">饼图</el-radio-button>
              <el-radio-button value="rose">玫瑰图</el-radio-button>
            </el-radio-group>
          </div>
        </div>
        <CategoryPieChart
          :data="expenseCategories"
          :type="expenseChartType"
          title="支出分类"
          class="chart-container"
        />
      </el-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import TrendChart from './TrendChart.vue'
import CategoryPieChart from './CategoryPieChart.vue'
import MemberBarChart from './MemberBarChart.vue'
import type {ChartsTrend, MemberBarChartData, CategoryPie} from "@/api/statistics/type.ts";

interface Props {
  trendDataMonth: ChartsTrend[]
  trendDataDay: ChartsTrend[]
  memberIncome: MemberBarChartData[]
  memberExpenses: MemberBarChartData[]
  incomeCategories: CategoryPie[]
  expenseCategories: CategoryPie[]
}

defineProps<Props>()

const trendChartTypeMonth = ref<'line' | 'bar'>('line')
const trendChartTypeDay = ref<'line' | 'bar'>('line')
const memberIncomeChartType = ref<'bar' | 'horizontal'>('bar')
const memberExpenseChartType = ref<'bar' | 'horizontal'>('bar')
const expenseChartType = ref<'pie' | 'rose'>('pie')
const incomeChartType = ref<'pie' | 'rose'>('pie')

</script>

<style scoped lang="scss">
.charts-container {
  margin-bottom: 20px;

  .charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;

    .chart-card {
      border-radius: 8px;
      height: 400px;
      padding-bottom: 20px;

      .chart-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 15px;

        .chart-title {
          font-size: 16px;
          font-weight: bold;
          color: var(--el-text-color-primary);
        }
      }

      .chart-container {
        width: 100%;
        height: 350px;

      }
    }


  }

  @media (max-width: 1200px) {
    .charts-row {
      grid-template-columns: 1fr;
    }
  }
}
</style>
